home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Microsoft Plateform / Visual Basic 5.0 / Msvb50.ace / msvb50 / MSVB50 / VB / SAMPLES / VISDATA / TABLEOBJ.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-10-16  |  29.7 KB  |  921 lines

  1. VERSION 5.00
  2. Begin VB.Form frmTableObj 
  3.    ClientHeight    =   3495
  4.    ClientLeft      =   1335
  5.    ClientTop       =   2625
  6.    ClientWidth     =   5580
  7.    Height          =   3960
  8.    HelpContextID   =   2016145
  9.    Icon            =   "TABLEOBJ.frx":0000
  10.    KeyPreview      =   -1  'True
  11.    Left            =   1275
  12.    LinkTopic       =   "Form1"
  13.    LockControls    =   -1  'True
  14.    MDIChild        =   -1  'True
  15.    ScaleHeight     =   3480
  16.    ScaleMode       =   0  'User
  17.    ScaleWidth      =   5593.989
  18.    ShowInTaskbar   =   0   'False
  19.    Tag             =   "Recordset"
  20.    Top             =   2220
  21.    Width           =   5700
  22.    Begin VB.PictureBox picViewButtons 
  23.       Align           =   1  'Align Top
  24.       Appearance      =   0  'Flat
  25.       BorderStyle     =   0  'None
  26.       ForeColor       =   &H80000008&
  27.       Height          =   705
  28.       Left            =   0
  29.       ScaleHeight     =   705
  30.       ScaleMode       =   0  'User
  31.       ScaleWidth      =   5577.292
  32.       TabIndex        =   1
  33.       TabStop         =   0   'False
  34.       Top             =   0
  35.       Width           =   5580
  36.       Begin VB.ComboBox cboIndexes 
  37.          BackColor       =   &H00FFFFFF&
  38.          BeginProperty Font 
  39.             Name            =   "Tahoma"
  40.             Size            =   8.25
  41.             Charset         =   0
  42.             Weight          =   400
  43.             Underline       =   0   'False
  44.             Italic          =   0   'False
  45.             Strikethrough   =   0   'False
  46.          EndProperty
  47.          Height          =   315
  48.          Left            =   720
  49.          Style           =   2  'Dropdown List
  50.          TabIndex        =   8
  51.          Top             =   360
  52.          Width           =   4335
  53.       End
  54.       Begin VB.CommandButton cmdSeek 
  55.          Caption         =   "&Seek"
  56.          BeginProperty Font 
  57.             Name            =   "Tahoma"
  58.             Size            =   8.25
  59.             Charset         =   0
  60.             Weight          =   400
  61.             Underline       =   0   'False
  62.             Italic          =   0   'False
  63.             Strikethrough   =   0   'False
  64.          EndProperty
  65.          Height          =   330
  66.          Left            =   2835
  67.          TabIndex        =   5
  68.          Top             =   0
  69.          Width           =   900
  70.       End
  71.       Begin VB.CommandButton cmdFilter 
  72.          Caption         =   "F&ilter"
  73.          BeginProperty Font 
  74.             Name            =   "Tahoma"
  75.             Size            =   8.25
  76.             Charset         =   0
  77.             Weight          =   400
  78.             Underline       =   0   'False
  79.             Italic          =   0   'False
  80.             Strikethrough   =   0   'False
  81.          EndProperty
  82.          Height          =   330
  83.          Left            =   3735
  84.          TabIndex        =   6
  85.          Top             =   0
  86.          Width           =   900
  87.       End
  88.       Begin VB.CommandButton cmdClose 
  89.          Cancel          =   -1  'True
  90.          Caption         =   "&Close"
  91.          BeginProperty Font 
  92.             Name            =   "Tahoma"
  93.             Size            =   8.25
  94.             Charset         =   0
  95.             Weight          =   400
  96.             Underline       =   0   'False
  97.             Italic          =   0   'False
  98.             Strikethrough   =   0   'False
  99.          EndProperty
  100.          Height          =   330
  101.          Left            =   4644
  102.          TabIndex        =   7
  103.          TabStop         =   0   'False
  104.          Top             =   0
  105.          Width           =   900
  106.       End
  107.       Begin VB.CommandButton cmdDelete 
  108.          Caption         =   "&Delete"
  109.          BeginProperty Font 
  110.             Name            =   "Tahoma"
  111.             Size            =   8.25
  112.             Charset         =   0
  113.             Weight          =   400
  114.             Underline       =   0   'False
  115.             Italic          =   0   'False
  116.             Strikethrough   =   0   'False
  117.          EndProperty
  118.          Height          =   330
  119.          Left            =   1935
  120.          TabIndex        =   4
  121.          Top             =   0
  122.          Width           =   900
  123.       End
  124.       Begin VB.CommandButton cmdEdit 
  125.          Caption         =   "&Edit"
  126.          BeginProperty Font 
  127.             Name            =   "Tahoma"
  128.             Size            =   8.25
  129.             Charset         =   0
  130.             Weight          =   400
  131.             Underline       =   0   'False
  132.             Italic          =   0   'False
  133.             Strikethrough   =   0   'False
  134.          EndProperty
  135.          Height          =   330
  136.          Left            =   1020
  137.          TabIndex        =   3
  138.          Top             =   0
  139.          Width           =   900
  140.       End
  141.       Begin VB.CommandButton cmdAdd 
  142.          Caption         =   "&Add"
  143.          BeginProperty Font 
  144.             Name            =   "Tahoma"
  145.             Size            =   8.25
  146.             Charset         =   0
  147.             Weight          =   400
  148.             Underline       =   0   'False
  149.             Italic          =   0   'False
  150.             Strikethrough   =   0   'False
  151.          EndProperty
  152.          Height          =   330
  153.          Left            =   0
  154.          TabIndex        =   2
  155.          Top             =   0
  156.          Width           =   1020
  157.       End
  158.       Begin VB.Label lblIndex 
  159.          Caption         =   "Index:"
  160.          BeginProperty Font 
  161.             Name            =   "Tahoma"
  162.             Size            =   8.25
  163.             Charset         =   0
  164.             Weight          =   400
  165.             Underline       =   0   'False
  166.             Italic          =   0   'False
  167.             Strikethrough   =   0   'False
  168.          EndProperty
  169.          Height          =   255
  170.          Left            =   120
  171.          TabIndex        =   24
  172.          Top             =   400
  173.          Width           =   615
  174.       End
  175.    End
  176.    Begin VB.PictureBox picFieldHeader 
  177.       Appearance      =   0  'Flat
  178.       BorderStyle     =   0  'None
  179.       ForeColor       =   &H80000008&
  180.       Height          =   240
  181.       Left            =   0
  182.       ScaleHeight     =   240
  183.       ScaleMode       =   0  'User
  184.       ScaleWidth      =   14948.92
  185.       TabIndex        =   21
  186.       Top             =   705
  187.       Width           =   14946
  188.       Begin VB.Label lblFieldValue 
  189.          Caption         =   " Value  (F4=Zoom) "
  190.          BeginProperty Font 
  191.             Name            =   "Tahoma"
  192.             Size            =   8.25
  193.             Charset         =   0
  194.             Weight          =   400
  195.             Underline       =   0   'False
  196.             Italic          =   0   'False
  197.             Strikethrough   =   0   'False
  198.          EndProperty
  199.          Height          =   255
  200.          Left            =   1680
  201.          TabIndex        =   23
  202.          Top             =   0
  203.          Width           =   3165
  204.       End
  205.       Begin VB.Label lblFieldHdr 
  206.          Caption         =   "Field Name:"
  207.          BeginProperty Font 
  208.             Name            =   "Tahoma"
  209.             Size            =   8.25
  210.             Charset         =   0
  211.             Weight          =   400
  212.             Underline       =   0   'False
  213.             Italic          =   0   'False
  214.             Strikethrough   =   0   'False
  215.          EndProperty
  216.          Height          =   252
  217.          Left            =   120
  218.          TabIndex        =   22
  219.          Top             =   0
  220.          Width           =   1212
  221.       End
  222.    End
  223.    Begin VB.PictureBox picChangeButtons 
  224.       BorderStyle     =   0  'None
  225.       Height          =   690
  226.       Left            =   0
  227.       ScaleHeight     =   690
  228.       ScaleMode       =   0  'User
  229.       ScaleWidth      =   5658.375
  230.       TabIndex        =   13
  231.       TabStop         =   0   'False
  232.       Top             =   0
  233.       Visible         =   0   'False
  234.       Width           =   5655
  235.       Begin VB.CommandButton cmdUpdate 
  236.          Caption         =   "&Update"
  237.          BeginProperty Font 
  238.             Name            =   "Tahoma"
  239.             Size            =   8.25
  240.             Charset         =   0
  241.             Weight          =   400
  242.             Underline       =   0   'False
  243.             Italic          =   0   'False
  244.             Strikethrough   =   0   'False
  245.          EndProperty
  246.          Height          =   372
  247.          Left            =   960
  248.          TabIndex        =   15
  249.          Top             =   48
  250.          Width           =   1212
  251.       End
  252.       Begin VB.CommandButton cmdCancel 
  253.          Caption         =   "&Cancel"
  254.          BeginProperty Font 
  255.             Name            =   "Tahoma"
  256.             Size            =   8.25
  257.             Charset         =   0
  258.             Weight          =   400
  259.             Underline       =   0   'False
  260.             Italic          =   0   'False
  261.             Strikethrough   =   0   'False
  262.          EndProperty
  263.          Height          =   372
  264.          Left            =   2640
  265.          TabIndex        =   14
  266.          Top             =   48
  267.          Width           =   1212
  268.       End
  269.    End
  270.    Begin VB.PictureBox picStatBox 
  271.       Align           =   2  'Align Bottom
  272.       Appearance      =   0  'Flat
  273.       BorderStyle     =   0  'None
  274.       ForeColor       =   &H80000008&
  275.       Height          =   285
  276.       Left            =   0
  277.       ScaleHeight     =   298.153
  278.       ScaleMode       =   0  'User
  279.       ScaleWidth      =   5584.009
  280.       TabIndex        =   19
  281.       TabStop         =   0   'False
  282.       Top             =   3204
  283.       Width           =   5580
  284.       Begin VB.CommandButton cmdNext 
  285.          Caption         =   ">"
  286.          Height          =   287
  287.          Left            =   4200
  288.          TabIndex        =   11
  289.          Top             =   0
  290.          Width           =   375
  291.       End
  292.       Begin VB.CommandButton cmdLast 
  293.          Caption         =   ">|"
  294.          Height          =   287
  295.          Left            =   4575
  296.          TabIndex        =   12
  297.          Top             =   0
  298.          Width           =   375
  299.       End
  300.       Begin VB.CommandButton cmdFirst 
  301.          Caption         =   "|<"
  302.          Height          =   287
  303.          Left            =   0
  304.          TabIndex        =   9
  305.          Top             =   0
  306.          Width           =   375
  307.       End
  308.       Begin VB.CommandButton cmdPrevious 
  309.          Caption         =   "<"
  310.          Height          =   287
  311.          Left            =   375
  312.          TabIndex        =   10
  313.          Top             =   0
  314.          Width           =   375
  315.       End
  316.       Begin VB.Label lblStatus 
  317.          BackColor       =   &H00FFFFFF&
  318.          BorderStyle     =   1  'Fixed Single
  319.          BeginProperty Font 
  320.             Name            =   "Tahoma"
  321.             Size            =   8.25
  322.             Charset         =   0
  323.             Weight          =   400
  324.             Underline       =   0   'False
  325.             Italic          =   0   'False
  326.             Strikethrough   =   0   'False
  327.          EndProperty
  328.          Height          =   285
  329.          Left            =   735
  330.          TabIndex        =   20
  331.          Top             =   0
  332.          Width           =   3360
  333.       End
  334.    End
  335.    Begin VB.VScrollBar vsbScrollBar 
  336.       Height          =   2616
  337.       LargeChange     =   3000
  338.       Left            =   5040
  339.       SmallChange     =   300
  340.       TabIndex        =   18
  341.       Top             =   960
  342.       Visible         =   0   'False
  343.       Width           =   252
  344.    End
  345.    Begin VB.PictureBox picFields 
  346.       Appearance      =   0  'Flat
  347.       BorderStyle     =   0  'None
  348.       ForeColor       =   &H80000008&
  349.       Height          =   375
  350.       Left            =   120
  351.       ScaleHeight     =   372
  352.       ScaleMode       =   0  'User
  353.       ScaleWidth      =   4812
  354.       TabIndex        =   16
  355.       TabStop         =   0   'False
  356.       Top             =   960
  357.       Width           =   4815
  358.       Begin VB.TextBox txtFieldData 
  359.          BackColor       =   &H00FFFFFF&
  360.          DataSource      =   "Data1"
  361.          BeginProperty Font 
  362.             Name            =   "Tahoma"
  363.             Size            =   8.25
  364.             Charset         =   0
  365.             Weight          =   400
  366.             Underline       =   0   'False
  367.             Italic          =   0   'False
  368.             Strikethrough   =   0   'False
  369.          EndProperty
  370.          ForeColor       =   &H00000000&
  371.          Height          =   288
  372.          Index           =   0
  373.          Left            =   1560
  374.          TabIndex        =   0
  375.          Top             =   0
  376.          Visible         =   0   'False
  377.          Width           =   3252
  378.       End
  379.       Begin VB.Label lblFieldName 
  380.          BeginProperty Font 
  381.             Name            =   "Tahoma"
  382.             Size            =   8.25
  383.             Charset         =   0
  384.             Weight          =   400
  385.             Underline       =   0   'False
  386.             Italic          =   0   'False
  387.             Strikethrough   =   0   'False
  388.          EndProperty
  389.          Height          =   252
  390.          Index           =   0
  391.          Left            =   0
  392.          TabIndex        =   17
  393.          Top             =   60
  394.          Visible         =   0   'False
  395.          Width           =   1572
  396.       End
  397.    End
  398. Attribute VB_Name = "frmTableObj"
  399. Attribute VB_Base = "0{529A44D1-C9E1-11CF-9ED2-00AA00574745}"
  400. Attribute VB_GlobalNameSpace = False
  401. Attribute VB_Creatable = False
  402. Attribute VB_TemplateDerived = False
  403. Attribute VB_PredeclaredId = True
  404. Attribute VB_Exposed = False
  405. Attribute VB_Customizable = False
  406. Option Explicit
  407. '>>>>>>>>>>>>>>>>>>>>>>>>
  408. Const BUTTON1 = "&Add"
  409. Const BUTTON2 = "&Edit"
  410. Const BUTTON3 = "&Delete"
  411. Const BUTTON4 = "&Close"
  412. Const BUTTON5 = "&Seek"
  413. Const BUTTON6 = "F&ilter"
  414. Const BUTTON7 = "&Cancel"
  415. Const BUTTON8 = "&Update"
  416. Const Label1 = "Field NAme:"
  417. Const Label2 = "Value (F4=Zoom)"
  418. Const MSG1 = "Add record"
  419. Const MSG2 = "Field Length Exceeded, Data Truncated!"
  420. Const MSG3 = "Delete Current Record?"
  421. Const MSG4 = "Edit record"
  422. Const MSG5 = "Enter Filter Expression:"
  423. Const MSG6 = "Opening Table"
  424. Const MSG7 = "Resizing Form"
  425. Const MSG8 = "Enter Seek Parameters"
  426. Const MSG9 = "Record Not Found"
  427. '>>>>>>>>>>>>>>>>>>>>>>>>
  428. 'form variables
  429. Public mrsFormRecordset As Recordset
  430. Dim msTableName As String        'form recordset table name
  431. Dim mvBookMark As Variant         'form bookmark
  432. Dim mbEditFlag As Integer        'edit mode
  433. Dim mbAddNewFlag As Integer      'add mode
  434. Dim mbDataChanged As Integer
  435. Dim mfrmSeek As New frmSeek      'seek form instance
  436. Dim mlNumRows As Long            'total rows in Table
  437. Private Sub cmdAdd_Click()
  438.   On Error GoTo AddErr
  439.   'set the mode
  440.   mrsFormRecordset.AddNew
  441.   lblStatus.Caption = MSG1
  442.   mbAddNewFlag = True
  443.   If mrsFormRecordset.RecordCount > 0 Then
  444.     mvBookMark = mrsFormRecordset.Bookmark
  445.   Else
  446.     mvBookMark = vbNullString
  447.   End If
  448.   picChangeButtons.Visible = True
  449.   picViewButtons.Visible = False
  450.   cmdNext.Enabled = False
  451.   cmdFirst.Enabled = False
  452.   cmdLast.Enabled = False
  453.   cmdPrevious.Enabled = False
  454.   ClearDataFields Me, mrsFormRecordset.Fields.Count
  455.   txtFieldData(0).SetFocus
  456.   Exit Sub
  457. AddErr:
  458.   ShowError
  459. End Sub
  460. Private Sub cmdCancel_Click()
  461.    On Error Resume Next
  462.    picChangeButtons.Visible = False
  463.    picViewButtons.Visible = True
  464.    cmdNext.Enabled = True
  465.    cmdFirst.Enabled = True
  466.    cmdLast.Enabled = True
  467.    cmdPrevious.Enabled = True
  468.    mbEditFlag = False
  469.    mbAddNewFlag = False
  470.    If Len(mvBookMark) > 0 Then mrsFormRecordset.Bookmark = mvBookMark
  471.    DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  472.    mbDataChanged = False
  473.    DBEngine.Idle dbFreeLocks
  474. End Sub
  475. Private Sub txtFieldData_Change(Index As Integer)
  476.   'just set the flag if data is changed
  477.   'it gets reset to false when a new record is displayed
  478.   mbDataChanged = True
  479. End Sub
  480. Private Sub txtFieldData_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
  481.   If KeyCode = &H73 Then   'F4
  482.     lblFieldName_DblClick Index
  483.   ElseIf KeyCode = 34 And vsbScrollBar.Visible Then
  484.     'pagedown with > 10 fields
  485.     vsbScrollBar.Value = vsbScrollBar.Value - 3000
  486.   ElseIf KeyCode = 33 And vsbScrollBar.Visible Then
  487.     'pageup with > 10 fields
  488.     vsbScrollBar.Value = vsbScrollBar.Value + 3000
  489.   End If
  490. End Sub
  491. Private Sub txtFieldData_KeyPress(Index As Integer, KeyAscii As Integer)
  492.   'only allow return when in edit of add mode
  493.   If mbEditFlag Or mbAddNewFlag Then
  494.     If KeyAscii = 13 Then
  495.       KeyAscii = 0
  496.       SendKeys "{Tab}"
  497.     End If
  498.   'throw away the keystrokes if not in add or edit mode
  499.   ElseIf mbEditFlag = False And mbAddNewFlag = False Then
  500.     KeyAscii = 0
  501.   End If
  502. End Sub
  503. Private Sub txtFieldData_LostFocus(Index As Integer)
  504.   On Error GoTo FldDataErr
  505.   If mbDataChanged Then
  506.     'store the data in the field
  507.     mrsFormRecordset(Index) = txtFieldData(Index)
  508.   End If
  509.   'reset for valid or error condition
  510.   mbDataChanged = False
  511.   Exit Sub
  512. FldDataErr:
  513.   ShowError
  514.   mbDataChanged = False
  515. End Sub
  516. Private Sub lblFieldName_DblClick(Index As Integer)
  517.   On Error GoTo ZoomErr
  518.   If mrsFormRecordset(Index).Type = dbText Or mrsFormRecordset(Index).Type = dbMemo Then
  519.      If mrsFormRecordset(Index).Type = dbText Then
  520.        gsZoomData = txtFieldData(Index).Text
  521.      ElseIf mrsFormRecordset(Index).FieldSize() < gnGETCHUNK_CUTOFF Then
  522.        gsZoomData = txtFieldData(Index).Text
  523.      Else
  524.        'add the rest of the field data with getchunk
  525.        MsgBar "Getting Memo Field Data", True
  526.        Screen.MousePointer = vbHourglass
  527.        gsZoomData = txtFieldData(Index).Text & StripNonAscii(mrsFormRecordset(Index).GetChunk(gnGETCHUNK_CUTOFF, gnMAX_MEMO_SIZE))
  528.        Screen.MousePointer = vbDefault
  529.        MsgBar vbNullString, False
  530.      End If
  531.      frmZoom.Caption = Mid(lblFieldName(Index).Caption, 1, Len(lblFieldName(Index).Caption) - 1)
  532.      frmZoom.Top = Top + 1200
  533.      frmZoom.Left = Left + 250
  534.      If mbAddNewFlag Or mbEditFlag Then
  535.        frmZoom.cmdsave.Visible = True
  536.        frmZoom.cmdCloseNoSave.Visible = True
  537.      Else
  538.        frmZoom.cmdClose.Visible = True
  539.      End If
  540.      If mrsFormRecordset(Index).Type = dbText Then
  541.        frmZoom.txtZoomData.Text = gsZoomData
  542.        frmZoom.Height = 1125
  543.      Else
  544.        frmZoom.txtMemo.Text = gsZoomData
  545.        frmZoom.txtMemo.Visible = True
  546.        frmZoom.txtZoomData.Visible = False
  547.        frmZoom.Height = 2205
  548.      End If
  549.      frmZoom.Show vbModal
  550.      If (mbAddNewFlag Or mbEditFlag) And gsZoomData <> "__CANCELLED__" Then
  551.        If mrsFormRecordset(Index).Type = dbText And Len(gsZoomData) > mrsFormRecordset(Index).Size Then
  552.          Beep
  553.          MsgBox MSG2, 48
  554.          txtFieldData(Index).Text = Mid(gsZoomData, 1, mrsFormRecordset(Index).Size)
  555.        Else
  556.          txtFieldData(Index).Text = gsZoomData
  557.        End If
  558.        mrsFormRecordset(Index) = txtFieldData(Index).Text
  559.        mbDataChanged = False
  560.      End If
  561.   End If
  562.   Exit Sub
  563. ZoomErr:
  564.   ShowError
  565. End Sub
  566. Private Sub cboIndexes_Click()
  567.   On Error GoTo IndErr
  568.   If mrsFormRecordset Is Nothing Then Exit Sub
  569.   If mrsFormRecordset.Index = Mid(cboIndexes.Text, 1, InStr(1, cboIndexes.Text, ":") - 1) Then Exit Sub
  570.   mrsFormRecordset.Index = Mid(cboIndexes.Text, 1, InStr(1, cboIndexes.Text, ":") - 1)
  571.   DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  572.   mbDataChanged = False
  573.   Exit Sub
  574. IndErr:
  575.   ShowError
  576. End Sub
  577. Private Sub cmdClose_Click()
  578.   Unload Me
  579. End Sub
  580. Private Sub vsbScrollBar_Change()
  581.   Dim nTop As Integer
  582.   nTop = vsbScrollBar
  583.   If (nTop - 960) Mod gnCTLARRAYHEIGHT = 0 Then
  584.     picFields.Top = nTop
  585.   Else
  586.     picFields.Top = ((nTop - 960) \ gnCTLARRAYHEIGHT) * gnCTLARRAYHEIGHT + 960
  587.   End If
  588. End Sub
  589. Private Sub cmdDelete_Click()
  590.   On Error GoTo DelRecErr
  591.   If MsgBox(MSG3, vbYesNo + vbQuestion) = vbYes Then
  592.     mrsFormRecordset.Delete
  593.     If gbTransPending Then gbDBChanged = True
  594.     If mrsFormRecordset.EOF = False Then
  595.       mrsFormRecordset.MoveNext
  596.     End If
  597.     mlNumRows = mlNumRows - 1
  598.     DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  599.     mbDataChanged = False
  600.   End If
  601.   Exit Sub
  602. DelRecErr:
  603.   ShowError
  604. End Sub
  605. Private Sub cmdEdit_Click()
  606.    On Error GoTo EditErr
  607.   Dim nDelay As Long
  608.   Dim nRetryCnt As Integer
  609.   Screen.MousePointer = vbHourglass
  610. RetryEdit:
  611.    mrsFormRecordset.Edit
  612.    lblStatus.Caption = MSG4
  613.    mbEditFlag = True
  614.    txtFieldData(0).SetFocus
  615.    mvBookMark = mrsFormRecordset.Bookmark
  616.    picChangeButtons.Visible = True
  617.    picViewButtons.Visible = False
  618.    cmdNext.Enabled = False
  619.    cmdFirst.Enabled = False
  620.    cmdLast.Enabled = False
  621.    cmdPrevious.Enabled = False
  622.    Screen.MousePointer = vbDefault
  623.    Exit Sub
  624. EditErr:
  625.   If Err = 3260 And nRetryCnt < gnMURetryCnt Then
  626.     nRetryCnt = nRetryCnt + 1
  627.     DBEngine.Idle dbFreeLocks
  628.     'Wait gnMUDelay seconds
  629.     nDelay = Timer
  630.     While Timer - nDelay < gnMUDelay
  631.       'do nothing
  632.     Wend
  633.     Resume RetryEdit
  634.   Else
  635.     ShowError
  636.   End If
  637. End Sub
  638. Private Sub cmdFilter_Click()
  639.   On Error GoTo FilterErr
  640.   Dim sFilter As String
  641.   Dim frmDyn As New frmDynaSnap
  642.   sFilter = InputBox(MSG5)
  643.   If Len(sFilter) = 0 Then Exit Sub
  644.   gsTableDynaFilter = "select * from " & AddBrackets(msTableName) & " where " & sFilter
  645.   frmDyn.Show                           'open recordset form w/ filtered table
  646.   gsTableDynaFilter = vbNullString
  647.   Exit Sub
  648. FilterErr:
  649.   ShowError
  650. End Sub
  651. Private Sub cmdFirst_Click()
  652.    On Error GoTo GoFirstError
  653.    mrsFormRecordset.MoveFirst
  654.    DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  655.    mbDataChanged = False
  656.    Screen.MousePointer = vbDefault
  657.    MsgBar vbNullString, False
  658.    Exit Sub
  659. GoFirstError:
  660.    ShowError
  661. End Sub
  662. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  663.   If mbEditFlag Or mbAddNewFlag Then Exit Sub
  664.   Select Case KeyCode
  665.     Case 35                'end
  666.       Call cmdLast_Click
  667.     Case 36                'home
  668.       Call cmdFirst_Click
  669.     Case 38                'up arrow
  670.       If Shift = 2 Then
  671.         Call cmdFirst_Click
  672.       Else
  673.         Call cmdPrevious_Click
  674.       End If
  675.     Case 40                'down arrow
  676.       If Shift = 2 Then
  677.         Call cmdLast_Click
  678.       Else
  679.         Call cmdNext_Click
  680.       End If
  681.   End Select
  682. End Sub
  683. Private Sub Form_Load()
  684.    Dim nFieldType As Integer
  685.    Dim i As Integer
  686.    Dim tdf As TableDef
  687.    Dim idx As Index
  688.    Dim sIndex As String
  689.    On Error GoTo TableErr
  690.    cmdAdd.Caption = BUTTON1
  691.    cmdEdit.Caption = BUTTON2
  692.    cmdDelete.Caption = BUTTON3
  693.    cmdClose.Caption = BUTTON4
  694.    cmdSeek.Caption = BUTTON5
  695.    cmdFilter.Caption = BUTTON6
  696.    cmdCancel.Caption = BUTTON7
  697.    cmdUpdate.Caption = BUTTON8
  698.    lblFieldHdr.Caption = Label1
  699.    lblFieldValue.Caption = Label2
  700.    Screen.MousePointer = vbHourglass
  701.    MsgBar MSG6, True
  702.    msTableName = mrsFormRecordset.Name
  703.    Set tdf = gdbCurrentDB.TableDefs(msTableName)
  704.    For Each idx In tdf.Indexes
  705.      sIndex = idx.Name
  706.      sIndex = sIndex & ":" & idx.Fields
  707.      If idx.Unique Then
  708.        sIndex = sIndex & ":Unique"
  709.      Else
  710.        sIndex = sIndex & ":Non-Unique"
  711.      End If
  712.      If idx.Primary Then
  713.        sIndex = sIndex & ":Primary"
  714.      End If
  715.      cboIndexes.AddItem sIndex
  716.    Next
  717.    'set the locking type
  718.    If gsDataType = gsMSACCESS Then
  719.      mrsFormRecordset.LockEdits = gnMULocking
  720.    End If
  721.    'show the first record
  722.    mlNumRows = mrsFormRecordset.RecordCount
  723.    'load the controls on the Table form
  724.    lblFieldName(0).Visible = True
  725.    txtFieldData(0).Visible = True
  726.    nFieldType = mrsFormRecordset.Fields(0).Type
  727.    txtFieldData(0).Width = GetFieldWidth(nFieldType)
  728.    txtFieldData(0).TabIndex = 0
  729.    If nFieldType = dbText Then txtFieldData(0).MaxLength = mrsFormRecordset.Fields(0).Size
  730.    For i = 1 To mrsFormRecordset.Fields.Count - 1
  731.      picFields.Height = picFields.Height + gnCTLARRAYHEIGHT
  732.      Load lblFieldName(i)
  733.      lblFieldName(i).Top = lblFieldName(i - 1).Top + gnCTLARRAYHEIGHT
  734.      lblFieldName(i).Visible = True
  735.      Load txtFieldData(i)
  736.      txtFieldData(i).Top = txtFieldData(i - 1).Top + gnCTLARRAYHEIGHT
  737.      txtFieldData(i).Visible = True
  738.      nFieldType = mrsFormRecordset.Fields(i).Type
  739.      txtFieldData(i).Width = GetFieldWidth(nFieldType)
  740.      txtFieldData(i).TabIndex = i
  741.      If nFieldType = dbText Then txtFieldData(i).MaxLength = mrsFormRecordset(i).Size
  742.    Next
  743.    'resize main window
  744.    If i <= 10 Then
  745.      Me.Height = ((i + 1) * gnCTLARRAYHEIGHT) + 1600
  746.    Else
  747.      Me.Height = 4668
  748.      Me.Width = Me.Width + 260
  749.      vsbScrollBar.Visible = True
  750.      vsbScrollBar.Min = 900
  751.      vsbScrollBar.Max = 900 - (i * gnCTLARRAYHEIGHT&) + 2500
  752.    End If
  753.    'display the field names
  754.    For i = 0 To mrsFormRecordset.Fields.Count - 1
  755.      lblFieldName(i).Caption = mrsFormRecordset(i).Name & ":"
  756.    Next
  757.    If cboIndexes.ListCount > 0 Then
  758.      cboIndexes.ListIndex = 0
  759.    Else
  760.      DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  761.      mbDataChanged = False
  762.    End If
  763.    Me.Width = 5508
  764.    Me.Left = 1000
  765.    Me.Top = 1000
  766.    Screen.MousePointer = vbDefault
  767.    MsgBar vbNullString, False
  768.    Exit Sub
  769. TableErr:
  770.    ShowError
  771.    Unload Me
  772. End Sub
  773. Private Sub Form_Resize()
  774.   On Error Resume Next
  775.   Dim nHeight As Integer
  776.   Dim i As Integer
  777.   Dim nTotWidth As Integer
  778.   If WindowState <> 1 Then   'not minimized
  779.     MsgBar MSG7, True
  780.     'make sure the form is lined up on a field
  781.     nHeight = Me.Height
  782.     If (nHeight - 1660) Mod gnCTLARRAYHEIGHT <> 0 Then
  783.       Me.Height = ((nHeight - 1660) \ gnCTLARRAYHEIGHT) * gnCTLARRAYHEIGHT + 1660
  784.     End If
  785.     'resize the status bar
  786.     picStatBox.Top = Me.Height - 650
  787.     'resize the scrollbar
  788.     vsbScrollBar.Height = picStatBox.Top - (picViewButtons.Top - picFieldHeader.Height) - 1200
  789.     vsbScrollBar.Left = Me.Width - 360
  790.     If mrsFormRecordset.Fields.Count > 10 Then
  791.       picFields.Width = Me.Width - 260
  792.       nTotWidth = vsbScrollBar.Left - 20
  793.     Else
  794.       picFields.Width = Me.Width - 20
  795.       nTotWidth = Me.Width - 50
  796.     End If
  797.     picFieldHeader.Width = Me.Width - 20
  798.     'widen the fields if possible
  799.     For i = 0 To mrsFormRecordset.Fields.Count - 1
  800.       lblFieldName(i).Width = 0.3 * nTotWidth
  801.       txtFieldData(i).Left = lblFieldName(i).Width + 20
  802.       If mrsFormRecordset(i).Type = dbText Or mrsFormRecordset(i).Type = dbMemo Then
  803.         txtFieldData(i).Width = 0.7 * nTotWidth - 250
  804.       End If
  805.     Next
  806.     lblFieldValue.Left = txtFieldData(0).Left
  807.     lblStatus.Width = Me.Width - 1600
  808.     cmdNext.Left = lblStatus.Width + 745
  809.     cmdLast.Left = cmdNext.Left + 370
  810.   End If
  811.   MsgBar vbNullString, False
  812. End Sub
  813. Private Sub Form_Unload(Cancel As Integer)
  814.   On Error Resume Next
  815.   Unload mfrmSeek   'get rid of attached seek form
  816.   mrsFormRecordset.Close          'close the form Table
  817.   DBEngine.Idle dbFreeLocks
  818.   MsgBar vbNullString, False
  819. End Sub
  820. Private Sub cmdLast_Click()
  821.    On Error GoTo GoLastError
  822.    mrsFormRecordset.MoveLast
  823.    'show the current record
  824.    DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  825.    mbDataChanged = False
  826.    Exit Sub
  827. GoLastError:
  828.    ShowError
  829. End Sub
  830. Private Sub cmdNext_Click()
  831.    On Error GoTo GoNextError
  832.    mrsFormRecordset.MoveNext
  833.    'show the current record
  834.    DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  835.    mbDataChanged = False
  836.    Exit Sub
  837. GoNextError:
  838.    ShowError
  839. End Sub
  840. Private Sub cmdPrevious_Click()
  841.    On Error GoTo GoPrevError
  842.    mrsFormRecordset.MovePrevious
  843.    'show the current record
  844.    DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  845.    mbDataChanged = False
  846.    Exit Sub
  847. GoPrevError:
  848.    ShowError
  849. End Sub
  850. Private Sub cmdSeek_Click()
  851.   On Error GoTo SeekErr
  852.   Dim sBookMark As String
  853.   If mrsFormRecordset.RecordCount = 0 Then Exit Sub
  854. SeekStart:
  855.   MsgBar MSG8, False
  856.   frmSeek.Show vbModal
  857.   If Len(gsSeekValue) = 0 Then
  858.     MsgBar vbNullString, False
  859.     Exit Sub
  860.   End If
  861.   sBookMark = mrsFormRecordset.Bookmark
  862.   Screen.MousePointer = vbHourglass
  863.   mrsFormRecordset.Seek gsSeekOperator, gsSeekValue
  864.   Screen.MousePointer = vbDefault
  865.   'return to old record if no match was found
  866.   If mrsFormRecordset.NoMatch And Len(sBookMark) > 0 Then
  867.     Beep
  868.     MsgBox MSG9, 48
  869.     mrsFormRecordset.Bookmark = sBookMark
  870.     GoTo SeekStart
  871.   End If
  872.   DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  873.   mbDataChanged = False
  874.   MsgBar vbNullString, False
  875.   Exit Sub
  876. SeekErr:
  877.   Screen.MousePointer = vbDefault
  878.   MsgBox Error
  879.   Exit Sub
  880. End Sub
  881. Private Sub cmdUpdate_Click()
  882.   On Error GoTo UpdateErr
  883.   Dim nDelay As Long
  884.   Dim nRetryCnt As Integer
  885.   Screen.MousePointer = vbHourglass
  886. RetryUpd:
  887.   mrsFormRecordset.Update
  888.   If gbTransPending Then gbDBChanged = True
  889.   If mbAddNewFlag Then
  890.     mlNumRows = mlNumRows + 1
  891.     mrsFormRecordset.MoveLast               'move to the new record
  892.   End If
  893.   mbEditFlag = False
  894.   mbAddNewFlag = False
  895.   picChangeButtons.Visible = False
  896.   picViewButtons.Visible = True
  897.   cmdNext.Enabled = True
  898.   cmdFirst.Enabled = True
  899.   cmdLast.Enabled = True
  900.   cmdPrevious.Enabled = True
  901.   DisplayCurrentRecord Me, mrsFormRecordset, mlNumRows, mbAddNewFlag
  902.   mbDataChanged = False
  903.   DBEngine.Idle dbFreeLocks
  904.   Screen.MousePointer = vbDefault
  905.   Exit Sub
  906. UpdateErr:
  907.   If Err = 3260 And nRetryCnt < gnMURetryCnt Then
  908.     nRetryCnt = nRetryCnt + 1
  909.     mrsFormRecordset.Bookmark = mrsFormRecordset.Bookmark   'Cancel the update
  910.     DBEngine.Idle dbFreeLocks
  911.     nDelay = Timer
  912.     'Wait gnMUDelay seconds
  913.     While Timer - nDelay < gnMUDelay
  914.       'do nothing
  915.     Wend
  916.     Resume RetryUpd
  917.   Else
  918.     ShowError
  919.   End If
  920. End Sub
  921.